package svmc.stp.hoaitt;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Palindrome {
        final static int NUM_TEST = 2;
        final static int NUM_CHAR = 8;

        static boolean isPalindrome(String s) {
                if (s.equals(new StringBuilder(s).reverse().toString())) {
                        return true;
                } else {
                        return false;
                }
        }

        static boolean isPalindromeChar(char[] A) {
                int i1 = 0;
                int i2 = A.length - 1;

                while (i2 > i1) {
                        if (A[i1] != A[i2]) {
                                return false;
                        }
                        ++i1;
                        --i2;

                }
                return true;

        }

        public static void main(String[] args) throws FileNotFoundException {
                // char[]A = {'a', 'b', 'c','b', 'a'};
                // System.out.println(isPalindromeChar(A));

                System.setIn(new FileInputStream("res/input_palindrome.txt"));
                Scanner sc = new Scanner(System.in);

                for (int test_case = 1; test_case <= NUM_TEST; test_case++) {
                        char[][] convert = new char[NUM_CHAR][NUM_CHAR];
                        int num_char_palindrome = sc.nextInt() ;

                        for (int i = 0; i < NUM_CHAR; i++) {
                                String data = sc.next();
                                convert[i] = data.toCharArray();
                        }

                        int count = 0;
                        int k;
                        for (int i = 0; i < 8; i++) {
                                for (int j = 0; j <= 8 - num_char_palindrome; j++) {
                                        for ( k = 0; k < num_char_palindrome/2; k++) {
                                                if (convert[i][j+k] != convert[i][j+num_char_palindrome-1-k]) {
                                                        break;
                                                }
                                        }
                                        if (k == num_char_palindrome/2) {
                                                count++;
                                        }
                                }
                        }

                        for (int j = 0; j < 8; j++) {
                                for (int i = 0; i <= 8 - num_char_palindrome; i++) {
                                        for ( k = 0; k < num_char_palindrome/2; k++) {
                                                if (convert[i+k][j] != convert[i+num_char_palindrome-1-k][j]) {
                                                        break;
                                                }
                                        }
                                        if (k == num_char_palindrome/2) {
                                                count++;
                                        }
                                }
                        }

                        System.out.println("#" + test_case + " " + count);
                }
                sc.close();

        }

}